
import { BasicFetchResult } from '../model/baseModel';
import { defHttp } from '@/utils/http/axios';
import { downloadBlob } from '@/utils/file/download';
const api = '/amsLeasedAsset';
// 租赁资源_根据资产ID查询
export const listLeasedAssetsByAssetId = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: api + '/listLeasedAssetsByAssetId',
    params,
  });
// 通过项目id查询租赁资源可添加查询条件
export const listLeasableAssets = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: api + '/listLeasableAssets',
    params,
  });

// 根据项目ID查询租赁资源
export const getListByProjectId = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: api + '/listByProjectId',
    params,
  });

// 租赁资源详情
export const getRelatedAssets = (id?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: api + '/getRelatedAssets/' + id,
  });

// 查询相关资源
export const getLeasedAssetDetail = (id?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: api + '/getLeasedAssetDetail/' + id,
  });
// 修改
export const editName = (params?: any) =>
  defHttp.post({ url: api + '/editName', params });

/**
 * 查询租赁资源分页
 * @author flc
 * @date 2023-05-17 15:51:48
 */
export const page = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: api + '/listLeasedAssets',
    params,
  });
/**
 * 添加租赁资源
 * @author flc
 * @date 2023-05-17 15:51:48
 */
export const add = (params?: any) =>
  defHttp.post({ url: api + '/add', params });
/**
 * 修改租赁资源
 * @author flc
 * @date 2023-05-17 15:51:48
 */
export const edit = (params?: any) =>
  defHttp.post({ url: api + '/edit', params });

/**
 * 删除租赁资源
 * @author flc
 * @date 2023-05-17 15:51:48
 */
export const del = (ids: string[]) =>
  defHttp.post({ url: api + '/delete', params: ids });
/**
 * 导出租赁资源
 * @author flc
 * @date 2023-05-17 15:51:48
 */
export const exp = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: api + '/export', params, timeout: -1 },
        { isReturnNativeResponse: true }
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
//批量停用
export const batchDeactivate = (ids: string[]) =>
  defHttp.post({ url: api + '/batchDeactivate', params: ids });

//  批量关闭
export const close = (ids: string[]) =>
  defHttp.post({ url: api + '/batchDisable', params: ids });
//批量启用
export const enable = (ids: string[]) =>
  defHttp.post({ url: api + '/batchEnable', params: ids });
